//
//  AlertPasswordViewController.m
//  JiuLe
//
//  Created by 黄鑫 on 16/8/30.
//  Copyright © 2016年 Fine. All rights reserved.
//

#import "AlertPasswordViewController.h"
#import "CLUIBaseViewController.h"

@interface AlertPasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textFieldOldPassword;
@property (weak, nonatomic) IBOutlet UITextField *textFieldNewPassword;
@property (weak, nonatomic) IBOutlet UITextField *textFieldReNawPassword;

@end

@implementation AlertPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    [self showNavgationWithLeftItemWithTitle:@"返回"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (IBAction)changPassword:(id)sender {
    if (_textFieldOldPassword.text.length == 0) {
        TIPSFORVIEW(@"原始密码不能为空！");
        return;
    } else if (_textFieldNewPassword.text.length == 0) {
        TIPSFORVIEW(@"新密码不能为空！");
        return;
    }else if (_textFieldReNawPassword.text.length == 0) {
        TIPSFORVIEW(@"确认密码不能为空！");
        return;
    }else if (![_textFieldNewPassword.text isEqualToString:_textFieldReNawPassword.text]) {
        TIPSFORVIEW(@"两次新密码不一致！");
        return;
    }
    [SVProgressHUD showWithStatus:@"修改密码..." maskType:SVProgressHUDMaskTypeClear];
    [[BaseDataRequest alloc] modifyUserPassward:_textFieldNewPassword.text oldPassword:_textFieldOldPassword.text withBlock:^(id responseObject, NSString *status, NSError *error) {
        [SVProgressHUD dismiss];
        if ([status isEqualToString:@"0"]) {
            [NSUserDefaults setObject:_textFieldNewPassword.text forKey:UserDataPassWord];
            //[SVProgressHUD showSuccessWithStatus:@"修改用户密码成功!"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            if (error != nil) {
                TIPSFORVIEW(@"请检测网络设置");
            }else{
                TIPSFORVIEW([responseObject objectForKey:@"message"]);
            }
        }
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
